package com.library.librarybackend.controller;

import com.library.librarybackend.domain.Result;
import com.library.librarybackend.domain.dto.BatchRegisterFormDTO;
import com.library.librarybackend.domain.dto.LoginFormDTO;
import com.library.librarybackend.domain.dto.RegisterFormDTO;
import com.library.librarybackend.domain.vo.UserVO;
import com.library.librarybackend.service.AuthService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
 * @author 平
 * @description 登录控制类
 * @since 2025-09-20 20:06
 */
@Tag(name = "登录控制类")
@RestController
@RequestMapping("/auth")
@RequiredArgsConstructor
public class AuthController {

    private final AuthService authService;

    @PostMapping("/login")
    @Operation(summary = "用户登录")
    public Result<UserVO> login(@RequestBody @Validated LoginFormDTO loginFormDTO) {
        return Result.success(authService.login(loginFormDTO));
    }

    @GetMapping("/logout")
    @Operation(summary = "用户登出")
    public Result<?> logout() {
        authService.logout();
        return Result.success();
    }

    @PostMapping("/register")
    @Operation(summary = "用户注册")
    public Result<?> register(@RequestBody @Validated RegisterFormDTO registerFormDTO) {
        authService.register(registerFormDTO);
        return Result.success();
    }

    @PostMapping("/batch/register")
    @Operation(summary = "批量用户注册")
    public Result<?> batchRegister(@RequestBody @Validated BatchRegisterFormDTO batchRegisterFormDTO) {
        authService.batchRegister(batchRegisterFormDTO);
        return Result.success();
    }

}
